package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingProjectServiceImpl
 * @Author lifuyun
 * @Date 2024-08-23
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 分页查询护理项目列表
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {

        //开启分页
        PageHelper.startPage(pageNum, pageSize);

        Page<NursingProjectVo> page = nursingProjectMapper.selectByPage(name, status);

        PageResponse<NursingProjectVo> pageResponse = new PageResponse(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     */
    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }

    /**
     * 根据id查询护理项目
     *
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        return BeanUtil.toBean(nursingProject, NursingProjectVo.class);
    }

    /**
     * 编辑护理项目
     *
     * @param nursingProject
     */
    @Override
    public void updateNursingProject(NursingProject nursingProject) {
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    /**
     * 护理项目启用禁用
     *
     * @param id
     * @param status
     */
    @Override
    public void updateNursingProjectStatus(long id, int status) {
        nursingProjectMapper.updateNursingProjectStatus(id, status);
    }

    /**
     * 根据id删除护理项目
     *
     * @param id
     */
    @Override
    public void deleteNursingProject(long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @Override
    public List<NursingProjectVo> getAllNursingProject() {
        List<NursingProjectVo> nursingProjectVoList = nursingProjectMapper.selectAllNursingProject();
        return nursingProjectVoList;
    }
}
